package com.yunhai.ucenter.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.ums.UmsPermission;
import com.yunhai.ucenter.service.SysMenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author mengze
 * @since 2023-08-23
 */
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    /**
     * 新增权限
     * */
    @PostMapping("")
    public Ret addMenu(@RequestBody UmsPermission sysMenu) throws Exception {

        sysMenuService.addMenu(sysMenu);
        return Ret.ok();
    }

    /**
     * 获取权限的树形菜单
     * */
    @GetMapping("/list")
    public Ret allMenuList() throws Exception {

        List<UmsPermission> sysMenus = sysMenuService.allMenuList();
        return Ret.ok( sysMenus );
    }

    /**
     * 获取权限的分页列表
     * */
    @GetMapping("/pagination")
    public Ret paginationMenuList( PaginationVo paginationVo ) throws Exception {

        IPage page = sysMenuService.paginationMenuList(paginationVo);
        return Ret.toPage(page);
    }

    /**
     * 更新权限
     * */
    @PutMapping("")
    public Ret updateMenu(@RequestBody UmsPermission sysMenu) throws Exception {

        sysMenuService.updateMenu(sysMenu);
        return Ret.ok();
    }

    /**
     * 批量删除权限
     * */
    @PostMapping("/batchRemove")
    public Ret batchRemoveMenu( @RequestBody List<Long> ids ) throws Exception {

        sysMenuService.batchRemoveMenu(ids);
        return Ret.ok();
    }
}

